<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentSiteTitle.class.php, $Author:  $ */



/** Component for generating site title
 * @version $Id: PhpFox_ComponentSiteTitle.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *
 */
class PhpFox_Mod_Site_ComponentSiteTitle extends BaseComponent
{
    function process()
    {   	
        $oReq = &App::getRequest();
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        App::loadClass('Text');
        $oText = &new Text();

        $sUser = $oSecurityService->getCurrentUserLogin();

        $sCurrentLogicUrl = App::getPageName();
        $sTitle = '';
        $aPageTitles = App::getParam('Mod_Site.page_title');

        $sMessagePrefix = 'Mod_Site.page_title.';
        $aUserPages = array
        (
            'uprofile',
            'ugallery',
            'uguestbook',
            'ublog',
            'ufriend',
            'ufavorite',
        );
        foreach ($aPageTitles as $sKey => $sRegExp)
        {
                if (preg_match('#'.$sRegExp.'#', $sCurrentLogicUrl))
                {
                    if ($sKey == 'home')
                    {
                        if ($sUser)
                        {
                            $sTitle .= App::format($sMessagePrefix.$sKey, $sUser);
                        }
                    }
                    elseif (in_array($sKey, $aUserPages))
                    {
                    	$sTitle .= $oReq->get('name').'&#146;s ';
                        $sTitle .= App::format($sMessagePrefix.$sKey);
                    }
                    else
                    {
                    	if ( App::isParamSet('Mod_Site.page_title.'. $sKey .'') )
                    	{
							$sTitle .= App::getParam('Mod_Site.page_title.'. $sKey .'');;
                    	}
                    	else
                    	{
                        	$sTitle .= App::format($sMessagePrefix.$sKey);
                        }
                    }
                    break;
                }
        }

        if ( ($sDir = $oReq->get('dir')) && ($sFile = $oReq->get('file')))
        {
        	$aContent = App::getParam('Mod_Site.content_page', $sDir);
        	if (isset($aContent[$sFile]))
        	{
        		$sTitle = ucwords(strtolower(App::format($aContent[$sFile])));
        	}
        }
        if ( $sFoxSeo = $oReq->get('title') )
        {
        	$sFoxSeo = str_replace(array("-","_")," ",$sFoxSeo);
			$sTitle .= App::getParam('title_delim');
			$sTitle .= trim($sFoxSeo);
        }
        if ($sSiteTitle = App::getSetting('site_title'))
        {
            $sTitle .= (!empty($sTitle) ? App::getParam('title_delim') : '');
            $sTitle .= $sSiteTitle;
        }
        if (App::removeBrand())
        {
            $sTitle .= ' (Powered by phpFoX)';
        }
        if ($this->getParam('escape'))
        {
            $sTitle = str_replace('\'', '\\\'', $sTitle);
        }

        $sTitle = str_replace('"', '&quot;', $sTitle);
        $sTitle = str_replace('\'', '&#8217;', $sTitle);
        $sTitle = str_replace('`', '&acute;', $sTitle);
        $sTitle = $oText->parseText($sTitle);
        return $sTitle;
    }
}
?>